//
//  HomeListView.swift
//  Video
//
//  Created by bnd on 2024/4/26.
//

import Foundation
import SwiftUI


struct HomeListView : View{
    var body: some View{
        return List(1...20, id: \.self) { index in
            // 添加跳转实现
            NavigationLink(
                destination: Text("Item #\(index) Details"),
                label: {
                    Text("Item #\(index)")
                        .font(.system(size: 20, weight: .bold, design: .rounded))
                })
        }
    }

}


struct HomeTapListView: View {
    @State private var items = ["Item 1", "Item 2", "Item 3"]
    @State private var editMode: EditMode = .inactive
    
    var body: some View {
        NavigationView{
            List {
                ForEach(items, id: \.self) { item in
                    Text(item)
                }
                .onMove(perform: move)
                .onDelete(perform: delete)
            }
            .environment(\.editMode, $editMode)
            .navigationBarTitle("Editable List")
            .navigationBarItems(
//                leading: EditButton(),
                trailing: Button(action: {
//                self.editMode.toggle()
                if editMode.isEditing {
                    editMode = .inactive
                } else {
                    editMode = .active
                }
            }) {
                if editMode.isEditing {
                    Text("Edit")
                } else {
                    Text("Done")
                }
            })
            
        }
    }
 
    func move(from source: IndexSet, to destination: Int) {
        items.move(fromOffsets: source, toOffset: destination)
    }
 
    func delete(at offsets: IndexSet) {
        items.remove(atOffsets: offsets)
    }
}
 
struct HomeTapListView_Previews: PreviewProvider {
    static var previews: some View {
        HomeTapListView()
    }
}
